package com.lm.hutool.example;

import cn.hutool.core.io.watch.WatchMonitor;
import cn.hutool.core.io.watch.Watcher;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchEvent;

public class HutoolWatchDogExample {
    public static void main(String[] args) {
        // 监控当前目录
        Path path = Paths.get("E:\\hutool");
        WatchMonitor monitor = WatchMonitor.createAll(path,new Watcher() {
            @Override
            public void onCreate(WatchEvent<?> event, Path currentPath) {
                System.out.println("文件创建：" + event.context());
            }

            @Override
            public void onModify(WatchEvent<?> event, Path currentPath) {
                System.out.println("文件修改：" + event.context());
            }

            @Override
            public void onDelete(WatchEvent<?> event, Path currentPath) {
                System.out.println("文件删除：" + event.context());
            }

            @Override
            public void onOverflow(WatchEvent<?> event, Path currentPath) {
                System.out.println("文件事件丢失");
            }
        });

        monitor.start();
    }
}